﻿#ifndef USBBOX_H
#define USBBOX_H
#include <QObject>
#include "protocol/serial.h"
#include "protocol/command.h"
typedef void(*UpdateFwNotify)(void *ctx, QString, int);

#define device_in_boot(s) (s != 0)

class UsbBox : public QObject
{
    Q_OBJECT
public:
    UsbBox(Serial *serial, QObject *parent = nullptr);
    bool UpdateFirmWare(QByteArray &data, int devaddr = 0x4D);
    bool GetVersion(QString &version, int devaddr = 0x4D);
    bool GetDevStatus(int &status, int devaddr = 0x4D);
    bool ResetDevice(int devaddr = 0x4D);
    void UpdateFwFromFile(QString fwFile, int addr){
        emit UpdateFwSignal(fwFile, addr);
    }
signals:
    void UpdateFwSignal(QString fwFile, int address);
    void UpdateNotifySignal(QString, int);
private:
    void UpdateFWNotify(QString s, int percent);
    int address;
    Serial *serial;
    QThread *work_thread;
};

#endif // USBBOX_H
